package Y2024.M11.D28;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;


/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 25228
 * Date: 2024-11-28
 * Time: 8:01
 */
public class Main {
    public static void main(String[] args) throws IOException {
        File file=new File("F:/Dir_1");
        file.mkdir();
        File txt=new File(file,"1.txt");
        txt.createNewFile();
        PrintWriter printWriter=new PrintWriter(txt);
        printWriter.println("This is a text file");
        printWriter.close();
        Scanner scanner=new Scanner(txt);
        int count=0;
        while (scanner.hasNextLine()){
            String s=scanner.nextLine();
            count +=count(s,'i');
        }
        System.out.println(count);
    }

    public static int count(String s, char i) {
        int c=0;
        for (int j = 0; j < s.length(); j++) {
            if (s.charAt(j)==i){
                c++;
            }
        }
        return c;
    }
}
